package com.tjcd.project.library_base.base.adapter.fragment;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.blankj.utilcode.util.ObjectUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * @Author jiangKunKun
 * @CreateDate 2021/11/17
 * @Description ViewPager2适配器
 * @SpittingGrooves
 */
public class ViewPagerTwoAdapter extends FragmentStateAdapter {
    private List<Fragment> mFragmentList;

    public ViewPagerTwoAdapter(@NonNull @NotNull FragmentActivity fragmentActivity, List<Fragment> fragmentList){
        super(fragmentActivity);
        mFragmentList = fragmentList;
    }

    @NonNull
    @NotNull
    @Override
    public Fragment createFragment(int position){
        return mFragmentList.get(position);
    }

    @Override
    public int getItemCount(){
        return ObjectUtils.isNotEmpty(mFragmentList) ? mFragmentList.size() : 0;
    }

    @Override
    public boolean containsItem(long itemId){
        return super.containsItem(itemId);
    }
}
